package com.hospital.demo.service.impl.dingyuxin;

import com.hospital.demo.mapper.dingyuxin.ExpendMapper;
import com.hospital.demo.mapper.dingyuxin.MoneyMapper;
import com.hospital.demo.model.dingyuxin.Expend;
import com.hospital.demo.model.dingyuxin.Money;
import com.hospital.demo.service.dingyuxin.DocterSer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DocterSerImpl implements DocterSer {

    @Autowired
    private MoneyMapper moneyMapper;

    @Autowired
    private ExpendMapper expendMapper;

    /**
     * 4.医生添加医院总余额
     */
    @Override
    public int addFinance(int addcount) {
        Money money = moneyMapper.selectByPrimaryKey(1);
        money.setTotalmoney(money.getTotalmoney() + addcount);
        moneyMapper.updateByPrimaryKey(money);
        return 0;
    }

    /**
     * 5.医生购买器材
     */
    @Override
    public int payInstallation(Expend expend) {
        expendMapper.insertSelective(expend);
        addFinance(-expend.getExpendmoney());
        return 0;
    }

    /**
     * 6.医生统计各项支出
     */
    @Override
    public Map<String, String> statistics() {
        int drug = expendMapper.selectByTypeMoney("药品");
        int device = expendMapper.selectByTypeMoney("设备");
        int insurance = expendMapper.selectByTypeMoney("医保");
        Map<String,String> res = new HashMap<>();
        res.put("drug",drug +"元");
        res.put("device",device +"元");
        res.put("insurance",insurance +"元");
        return res;
    }

    /**
     * 显示医院总金额
     */
    @Override
    public int allMoney() {
        return moneyMapper.selectByPrimaryKey(1).getTotalmoney();
    }

    /**
     * 显示所有支出
     */
    @Override
    public List<Expend> allExpend() {
        return expendMapper.selectAll();
    }

    @Override
    public List<Expend> findExpendByType(String type) {
        return expendMapper.selectByType(type);
    }
}
